package com.codedancer.campus.mapper;

import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.codedancer.campus.common.core.BaseMapper;
import com.codedancer.campus.po.CommodityCollection;

public interface CommodityCollectionMapper extends BaseMapper<CommodityCollection> {

    /**
     * 是否收藏
     *
     * @param uuid
     * @param currentLoginUuid
     * @return
     */
    default Boolean isCollect(String uuid, String currentLoginUuid) {
        LambdaQueryWrapper<CommodityCollection> lambdaQueryWrapper = new LambdaQueryWrapper<>();
        lambdaQueryWrapper.eq(CommodityCollection::getCollectUserUuid, currentLoginUuid);
        lambdaQueryWrapper.eq(CommodityCollection::getCommodityUuid, uuid);
        return selectCount(lambdaQueryWrapper) > 0;
    }

    /**
     * 取消收藏
     *
     * @param uuid
     * @param currentLoginUuid
     */
    default void cancelCollect(String uuid, String currentLoginUuid) {
        LambdaQueryWrapper<CommodityCollection> lambdaQueryWrapper = new LambdaQueryWrapper<>();
        lambdaQueryWrapper.eq(CommodityCollection::getCollectUserUuid, currentLoginUuid);
        lambdaQueryWrapper.eq(CommodityCollection::getCommodityUuid, uuid);
        delete(lambdaQueryWrapper);
    }
}
